package com.example.batchdemo.controller;

import com.example.batchdemo.service.UserService;
import com.example.batchdemo.util.HttpResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * TODO
 *
 * @ClassName TestController
 * @Author xiaojiang
 * @Date 2022/2/24 下午 17:27
 */
@RequiredArgsConstructor
@RestController
@CrossOrigin(origins = "*") //在控制器(类上)上使用注解 @CrossOrigin:，表示该类的所有方法允许跨域。也可以在方法上使用注解 @CrossOrigin:
public class TestController {

    final UserService userService;

    @RequestMapping(value = "/get_user", method = RequestMethod.GET)
    public HttpResult getUser(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize, HttpServletResponse response) {
        // 使用 HttpServletResponse 对象添加响应头(Access-Control-Allow-Origin)来授权原始域，这里 Origin的值也可以设置为 “*”,表示全部放行。
        response.addHeader("Access-Allow-Control-Origin","*");
        System.out.println("准备查询记录！");
        return userService.GetAll(page,pageSize);
    }



}
